package com.weitu.workflow.definition.eventListener;


import com.weitu.workflow.flowManagement.service.FlowManagementService;
import com.weitu.workflow.flowManagement.service.impl.FlowManagementServiceImpl;
import org.fireflow.engine.*;
import org.fireflow.engine.persistence.IPersistenceService;
import org.fireflow.engine.taskinstance.DefaultTaskInstanceEventListener;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * FormTask监听
 * 
 * @author zhangxuebing
 */
public class FormTaskEventListener extends DefaultTaskInstanceEventListener {
	@Autowired
	private FlowManagementService flowManagementService;//工作流管理service
	@Autowired
	private RuntimeContext runtimeContext;

	public FormTaskEventListener() {
		super();
	}

	@Override
	protected void beforeTaskInstanceStart(IWorkflowSession currentSession, IProcessInstance processInstance, ITaskInstance taskInstance) throws EngineException {
		super.beforeTaskInstanceStart(currentSession, processInstance, taskInstance);
	}

	@Override
	protected void afterTaskInstanceCompleted(IWorkflowSession currentSession, IProcessInstance processInstance, ITaskInstance taskInstance) throws EngineException {
		IPersistenceService persistenceService=runtimeContext.getPersistenceService();
		List<IWorkItem> workItems = persistenceService.findWorkItemsForTaskInstance(taskInstance.getId());
		super.afterTaskInstanceCompleted(currentSession, processInstance, taskInstance);
	}

	@Override
	protected void afterWorkItemCreated(IWorkflowSession currentSession, IProcessInstance processInstance, ITaskInstance taskInstance, IWorkItem workItem) throws EngineException {
		super.afterWorkItemCreated(currentSession, processInstance, taskInstance, workItem);
	}
}
